package com.streamtest;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;

public class LambdaTest {
    public static void main(String[] args) {

        List<People> people = new ArrayList<>();
        people.add(new People(25, "Alice"));
        people.add(new People(30, "Bob"));
        people.add(new People(25, "Charlie"));
        people.add(new People(20, "David"));

        // 先按年龄降序排序，年龄相同则按名字降序排序
        List<People> sortedPeople = people.stream()
                .sorted(Comparator.comparingInt(People::getAge).reversed()
                        .thenComparing(People::getName, Comparator.reverseOrder()))
                .collect(Collectors.toList());

        sortedPeople.forEach(System.out::println);
    }

    public static void printNum(IntPredicate predicate){
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            if(predicate.test(i)){
                System.out.println(i);
            }
        }
    }

    public static <R> R typeConver(Function<String,R> function){
        String str = "1235";
        R result = function.apply(str);
        return result;
    }


}
